//
//  HYCollectionViewCellForT13.m
//  TTLestening
//
//  Created by dllo on 16/3/28.
//  Copyright © 2016年 dilo. All rights reserved.
//

#import "HYCollectionViewCellForT13.h"
#import "HYModelForRecommend.h"
#import "HYCollectionViewCellImage.h"
#import <SDWebImage/UIImageView+WebCache.h>

@interface HYCollectionViewCellForT13 () <UICollectionViewDataSource, UICollectionViewDelegate>

@property (nonatomic, retain) UILabel *labelTitle;
@property (nonatomic, retain) UILabel *labelDes;
@property (nonatomic, retain) UICollectionView *collectionView;
@property (nonatomic, retain) UICollectionViewFlowLayout *flowLayout;
@property (nonatomic, retain) UIButton *buttonPlay;

@property (nonatomic, retain) NSArray *arrForURL;

@end

@implementation HYCollectionViewCellForT13

#pragma mark - init
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubViews];
    }
    return self;
}

#pragma mark - createSubViews
- (void)createSubViews {
    
    self.labelDes = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelDes];
    self.labelDes.textAlignment = 1;
    self.labelDes.font = [UIFont systemFontOfSize:14];
    self.labelDes.textColor = [UIColor grayColor];
    
    self.labelTitle = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelTitle];
    self.labelTitle.textAlignment = 1;
    self.labelTitle.font = [UIFont boldSystemFontOfSize:16];
    
    self.flowLayout = [[UICollectionViewFlowLayout alloc] init];
    self.flowLayout.minimumLineSpacing = 0;
    self.flowLayout.minimumInteritemSpacing = 0;
    self.flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    self.flowLayout.itemSize = CGSizeMake(self.contentView.frame.size.width / 3, self.contentView.frame.size.height / 3 / 2);
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, self.contentView.frame.size.height / 5 * 2, self.contentView.frame.size.width, self.contentView.frame.size.height / 5 * 3) collectionViewLayout:self.flowLayout];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    [self.contentView addSubview:self.collectionView];
    
    self.buttonPlay = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.buttonPlay setImage:[UIImage imageNamed:@"iconfont-bofang-3"] forState:UIControlStateNormal];
    [self.contentView addSubview:self.buttonPlay];
    [self.buttonPlay addTarget:self action:@selector(addToPlay) forControlEvents:UIControlEventTouchUpInside];
    
}
- (void)addToPlay {
    
    NSLog(@"暂未实现13");
}

#pragma mark - layout
- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.flowLayout.minimumLineSpacing = 0;
    self.flowLayout.minimumInteritemSpacing = 0;
    
    self.flowLayout.itemSize = CGSizeMake(self.collectionView.frame.size.width / 3, self.collectionView.frame.size.height / 2);
    
    self.collectionView.frame = CGRectMake(0, self.contentView.frame.size.height / 5 * 2, self.contentView.frame.size.width, self.contentView.frame.size.height / 5 * 3);
    [self.collectionView registerClass:[HYCollectionViewCellImage class] forCellWithReuseIdentifier:@"colPoolForReImage"];
    
    self.labelDes.frame = CGRectMake(0, 0, self.contentView.frame.size.width - 40, 30);
    self.labelDes.center = CGPointMake(self.contentView.frame.size.width / 2, self.contentView.frame.size.height / 6);
    
    self.labelTitle.frame = CGRectMake(0, 0, self.contentView.frame.size.width - 40, 30);
    self.labelTitle.center = CGPointMake(self.contentView.frame.size.width / 2, self.contentView.frame.size.height / 6 + 30);
    
    self.buttonPlay.frame = CGRectMake(0, 0, 50, 50);
    self.buttonPlay.center = self.collectionView.center;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    HYCollectionViewCellImage *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"colPoolForReImage" forIndexPath:indexPath];
    [cell passModel:self.arrForURL[indexPath.item]];
    
    return cell;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 6;
}

- (void)passMoldel:(HYModelForRecommend *)model {
    
    // tyep为13时和22时使用smallPicUrls.
    
    self.labelTitle.text = model.name;
    self.labelDes.text = model.reason;
    
    self.arrForURL = model.smallPicUrls;
}







@end
